package ynu.edu.online_course.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ynu.edu.online_course.entity.UserExtension;
import ynu.edu.online_course.service.UserExtensionService;

@RestController
@RequestMapping("/user-extensions")
public class UserExtensionController {

    @Autowired
    private UserExtensionService userExtensionService;

    // 获取用户扩展信息
    @GetMapping("/user/{userId}")
    public ResponseEntity<?> getUserExtension(@PathVariable Long userId) {
        UserExtension extension = userExtensionService.getExtensionByUserId(userId);
        return ResponseEntity.ok(extension);
    }

    // 添加用户扩展信息
    @PostMapping
    public ResponseEntity<?> addUserExtension(@RequestBody UserExtension userExtension) {
        userExtensionService.addUserExtension(userExtension);
        return ResponseEntity.ok("User extension added successfully");
    }

    // 更新用户扩展信息
    @PutMapping("/{id}")
    public ResponseEntity<?> updateUserExtension(@PathVariable Long id, @RequestBody UserExtension userExtension) {
        userExtension.setUserId(id);
        userExtensionService.updateUserExtension(userExtension);
        return ResponseEntity.ok("User extension updated successfully");
    }
}
